package weekMatch.two_103;

public class LeeCode_03 {
    public static void main(String[] args) {

    }
    private static int findMaxFish(int[][] grid) {
        int m = grid.length;
        int n = grid[0].length;
        int ans = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (grid[i][j] > 0){
                    if (grid[i][j] == 100){
                        continue;
                    }
                    int[] sum = new int[1];
                    dfs(grid, i, j, sum);
                    ans = Math.max(ans, sum[0]);
                }
            }
        }
        return ans;
    }
    private static void dfs(int[][] grid, int i, int j, int[] sum){
        int m = grid.length;
        int n = grid[0].length;
        if (i < 0 || i >= m){
            return;
        }
        if (j < 0 || j >= n){
            return;
        }
        if (grid[i][j] == 100 || grid[i][j] == 0){
            return;
        }
        sum[0] += grid[i][j];
        grid[i][j] = 100;
        dfs(grid, i + 1, j, sum);
        dfs(grid, i - 1, j, sum);
        dfs(grid, i, j + 1, sum);
        dfs(grid, i, j - 1, sum);
    }
}
